/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ill_be_bach;

import ill_be_bach.model.Accidental;
import ill_be_bach.model.Beat;
import ill_be_bach.model.Chord;
import ill_be_bach.model.Key;
import ill_be_bach.model.Note;
import ill_be_bach.model.Song;
import java.awt.Toolkit;
import java.util.TimerTask;

/**
 *
 * @author Abhi
 */
public class RecorderTask extends TimerTask {

    private Song song ;
    private Toolkit beeper ;
    private int iterCount = 0 ;
    private boolean trebleNoteReceived = false ;
    private boolean bassNoteReceived = false ;


    public RecorderTask(Song song) {
        super();
        this.song = song ;
        this.beeper = Toolkit.getDefaultToolkit();
    }

    public void run() {
        iterCount++ ;
        if (iterCount % 2 == 0) {
            beeper.beep();
        }

        if (!trebleNoteReceived) {
            //song.addNote(new Note(Key.Rest, Accidental.None, 0), 0, false, Beat.EIGHTH);
        }
        if (!bassNoteReceived) {
            //song.addNote(new Note(Key.Rest, Accidental.None, 0), 1, false, Beat.EIGHTH);
        }

        trebleNoteReceived = false ;
        bassNoteReceived = false ;
    }

    private void receive() {
        Chord chord = null ; // TODO: receive note from keyboard and process
        int voice = chord.notes.get(0).octave > 4 ? 0 : 1 ;
        song.addChord(chord, voice);
        
        trebleNoteReceived = voice == 0 ;
        bassNoteReceived = voice == 1 ;
    }
}
